package com.cmcc.aregister.ui.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.model.MastEntity;

public class DocChooseAdapter extends BaseAdapter {

    private List<MastEntity> list;

    private Context context;

    public DocChooseAdapter(Context context, List<MastEntity> dataList) {
        super();
        this.context = context;
        this.list = dataList;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(
                R.layout.doc_list, null);
            holder.doc_name = (TextView) convertView
                .findViewById(R.id.doc_name);
            holder.left_num = (TextView) convertView
                .findViewById(R.id.left_num);
            holder.to_date = (TextView) convertView.findViewById(R.id.to_date);
            holder.time_type = (TextView) convertView
                .findViewById(R.id.time_type);
            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.doc_name.setText(list.get(position).doctor_name);
        holder.left_num.setText(context.getString(R.string.left_num) + "("
            + list.get(position).left_num + ")");
        holder.to_date.setText(list.get(position).to_date);
        holder.time_type.setText(list.get(position).time_type_desc);
        return convertView;
    }

    static class ViewHolder {
        TextView doc_name;
        TextView left_num;
        TextView to_date;
        TextView time_type;
    }

}